package com.cz.ssyx.activity.api;

import com.cz.ssyx.activity.service.ActivityInfoService;
import com.cz.ssyx.activity.service.CouponInfoService;
import com.cz.ssyx.model.activity.ActivityInfo;
import com.cz.ssyx.model.activity.CouponInfo;
import com.cz.ssyx.model.order.CartInfo;
import com.cz.ssyx.vo.order.CartInfoVo;
import com.cz.ssyx.vo.order.OrderConfirmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @descriptions:
 * @author: Joker.
 * @date: 2024/4/28 22:57
 * @version: 1.0
 */

@RestController
@RequestMapping("api/activity")
public class ActivityInfoApiController {

    @Autowired
    private ActivityInfoService activityInfoService;

    @Autowired
    private CouponInfoService couponInfoService;

    @PostMapping("inner/findActivity")
    public Map<Long, List<String>> findActivity(@RequestBody List<Long> skuEsIdList){
        Map<Long, List<String>> skuIdRuleListMap = activityInfoService.findActivity(skuEsIdList);
        return skuIdRuleListMap;
    }

    //获取商品的活动信息和优惠券
    @GetMapping("inner/findActivityAndCoupon/{skuId}/{userId}")
    public Map<String, Object> findActivityAndCoupon(@PathVariable Long skuId,
                                                     @PathVariable Long userId){
        return activityInfoService.findActivityAndCoupon(skuId, userId);
    }

    //获取带有优惠活动和优惠券的购物车信息
    @PostMapping("inner/findCartActivityAndCoupon/{userId}")
    OrderConfirmVo findCartActivityAndCoupon(@PathVariable("userId") Long userId,
                                             @RequestBody List<CartInfo> cartInfoList) {
        return activityInfoService.findCartActivityAndCoupon(cartInfoList, userId);
    }

    //把购物车里的每个商品都按照活动分组
    @PostMapping("inner/findCartActivityList")
    public List<CartInfoVo> findCartActivityList(@RequestBody List<CartInfo> cartInfoList) {
        return activityInfoService.findCartActivityList(cartInfoList);
    }

    //获取购物车对应优惠券
    @PostMapping("inner/findRangeSkuIdList/{couponId}")
    public CouponInfo findRangeSkuIdList(@RequestBody List<CartInfo> cartInfoList,
                                         @PathVariable Long couponId) {
        return couponInfoService.findRangeSkuIdList(cartInfoList, couponId);
    }

    //更新优惠券的使用状态
    @GetMapping("inner/updateCouponInfoUseStatus/{couponId}/{userId}/{orderId}")
    public Boolean updateCouponInfoUseStatus(@PathVariable("couponId") Long couponId,
                                             @PathVariable("userId") Long userId,
                                             @PathVariable("orderId") Long orderId) {
        return couponInfoService.updateCouponInfoUseStatus(couponId, userId, orderId);
    }
}
